package com.naiterui.ehp.bs.weixin.handler;

import com.naiterui.ehp.bs.weixin.service.WechatService;
import java.util.Map;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

/**
 * @author gaoll gll910802@163.com
 */
@Component
@AllArgsConstructor
public class UnsubscribeHandler extends AbstractHandler {

    private final WechatService wechatService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
        WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {

        logger.info("UnsubscribeHandler , wxMessage={}", wxMessage);
        String openId = wxMessage.getFromUser();

        wechatService.unsubscribe(openId, wxMpService);
        return null;
    }

}
